package app.repositories.impl;

import javax.persistence.EntityManager;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import app.models.Perfil;
import app.repositories.PerfilRepository;
import app.repositories.Repository;
import app.util.Constants;
import br.com.caelum.vraptor.ioc.Component;

@Component
public class PerfilRepositoryImpl extends Repository<Perfil, Long> implements PerfilRepository{

	protected PerfilRepositoryImpl(EntityManager entityManager) {
		super(entityManager);
	}
	
	public Perfil findPerfilByName(String perfilName){
		Criteria criteria = createCriteria();
		
		criteria.add(Restrictions.eq(Constants.NOME, perfilName));
		
		return (Perfil) criteria.uniqueResult();
	}

}
